package adv.i31.robot;

import android.opengl.GLES20;

public class VertexShader {

	private int vertexShaderHandle;

	public int getVertexShaderHandle() {
		return vertexShaderHandle;
	}

	public void setVertexShaderHandle(int vertexShaderHandle) {
		this.vertexShaderHandle = vertexShaderHandle;
	}

	public VertexShader(final String code) {
		// Load in the vertex shader.
		vertexShaderHandle = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);

		if (vertexShaderHandle != 0) {
			// Pass in the shader source.
			GLES20.glShaderSource(vertexShaderHandle, code);

			// Compile the shader.
			GLES20.glCompileShader(vertexShaderHandle);

			// Get the compilation status.
			final int[] compileStatus = new int[1];
			GLES20.glGetShaderiv(vertexShaderHandle, GLES20.GL_COMPILE_STATUS, compileStatus, 0);

			// If the compilation failed, delete the shader.
			if (compileStatus[0] == 0) {
				GLES20.glDeleteShader(vertexShaderHandle);
				vertexShaderHandle = 0;
			}
		}

		if (vertexShaderHandle == 0) {
			throw new RuntimeException("Error creating vertex shader.");
		}
	}
}
